/*
 * @lc app=leetcode.cn id=897 lang=javascript
 *
 * [897] 递增顺序搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */

var inorder = function (root, head) {
  if (root === null) return null;
  inorder(root.right, head);
  head.push(root.val);
  inorder(root.left, head);
}

/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var increasingBST = function (root) {
  const head = [];
  inorder(root, head);
  let cur;
  head.forEach(node=>{
    cur = new TreeNode(node, null, cur);
  })
  return cur;
};
// @lc code=end

